package org.csu.demo.controller.front;

import lombok.Getter;
import org.apache.ibatis.annotations.Param;
import org.csu.demo.common.CommonResponse;
import org.csu.demo.entity.Category;
import org.csu.demo.entity.Product;
import org.csu.demo.service.CatalogService;
import org.csu.demo.vo.ItemVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/catalog/")
public class CatalogController {

    @Autowired
    private CatalogService catalogService;

    //返回陈列Category的列表
    @GetMapping("categories")
    @ResponseBody
    public CommonResponse<List<Category>> getCategoryList(){
        return catalogService.getCategoryList();
    }

    //返回特定的Category
    @GetMapping("categories/{id}")
    @ResponseBody
    public CommonResponse<Category> getCategoryById(@PathVariable("id") String  categoryId){
        return catalogService.getCategoryById(categoryId);
    }

    //返回特定Category的陈列Product的列表
    @GetMapping("categories/{id}/products")
    @ResponseBody
    public CommonResponse<List<Product>> getProductListByCategoryId(@PathVariable("id") String productId){
        return catalogService.getProductListByCategoryId(productId);
    }

    //返回特定Product
    @GetMapping("products/{id}")
    @ResponseBody
    public CommonResponse<Product> getProductById(@PathVariable("id") String productId){
        return catalogService.getProductById(productId);
    }

    //返回特定Product的陈列Item的列表
    @GetMapping("products/{id}/items")
    @ResponseBody
    public CommonResponse<List<ItemVO>> getItemsByProductId(@PathVariable("id") String productId){
        return catalogService.getItemsByProductId(productId);
    }

    //返回特定Item

}
